package com.guigu.liuzhireng.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.liuzhireng.mapper.AuthorizationMapper;
import com.guigu.liuzhireng.pojo.Authorization;
import com.guigu.liuzhireng.pojo.PageVo;
import com.guigu.liuzhireng.service.AuthorizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AuthorizationServiceImpl implements AuthorizationService {

    @Autowired
    AuthorizationMapper authorizationMapper;

    public List<String> QueryAuth(String account) {
        List<Authorization> list = authorizationMapper.authAll(account);

        List<String> listStr=new ArrayList<>();
        for (Authorization a : list) {
            listStr.add(a.getAuurl());
        }
        return listStr;
    }

    @Override
    public int update(Authorization authorization) {
        return authorizationMapper.updateByPrimaryKeySelective(authorization);
    }

    @Override
    public int insert(Authorization authorization) {
        return authorizationMapper.insert(authorization);
    }

    @Override
    public int delete(Integer id) {
        return authorizationMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageVo<Authorization> Page(Authorization authorization, int num, int size) {
        PageHelper.startPage(num,size);
        List<Authorization> list = authorizationMapper.Auths(authorization);
        PageInfo<Authorization> pageInfo = new PageInfo<>(list);
        PageVo<Authorization> pageVo = new PageVo<>();
        pageVo.setTotal(pageInfo.getTotal());
        pageVo.setRows(pageInfo.getList());
        return pageVo;
    }


}
